package com.adtech.core.exception;

import java.lang.reflect.InvocationTargetException;

import ognl.OgnlException;

/**
 * 涉及反射和BeanUtil等操作所发生的异常，都转换成该异常，系统捕获处理。
 *
 * @since 2011-10-20
 * @author Dormin
 *
 * @Copyright (C) AD Tech Workshop All Right Reserved
 */
public class ReflectException extends SystemException {

	private static final long serialVersionUID = -4269415950446034553L;

	public ReflectException(Throwable cause) {
		super(0, cause);
		super.setErrorCode(getErrorCode(cause));
	}

	private int getErrorCode(Throwable cause){
		if (cause instanceof ClassNotFoundException){
			return ErrorCode.CLASS_NOT_FOUND;
		} else if (cause instanceof InvocationTargetException){
			return ErrorCode.INVOCATION_TARGET;
		} else if (cause instanceof InstantiationException){
			return ErrorCode.INSTANTIATION;
		} else if (cause instanceof NoSuchMethodException){
			return ErrorCode.NO_SUCH_METHOD;
		} else if (cause instanceof OgnlException){
			return ErrorCode.OGNL_EXCEPTION;
		} else if (cause instanceof IllegalAccessException){
			return ErrorCode.ILLEGAL_ACCESS;
		} else {
			return ErrorCode.SYSTEM_UNKNOWN_ERROR;
		}
	}

}
